﻿
Imports osi.root.connector

Partial Public Class _pointer(Of T)
#If Not (PocketPC OrElse Smartphone) Then
    Public Shared Operator ^(ByVal p As _pointer(Of T), ByVal ji As Decimal) As Object
        On Error GoTo finish
        Dim p2 As Object = Nothing
        p2 = p
        Dim jumps As Int64 = 0
        jumps = Math.Truncate(ji)
        While jumps > 0
            p2 = +(cast(Of _pointer(Of T))(p2, False))
            jumps -= 1
        End While
finish:
        Return p2
    End Operator
#End If

    Public Shared Operator +(ByVal p As _pointer(Of T)) As T
        Return If(p Is Nothing, Nothing, p.get())
    End Operator

    'special treatment for pointer, it compares reference equaling, instead of internal object
    Public Shared Operator <>(ByVal this As _pointer(Of T), ByVal that As _pointer(Of T)) As Boolean
        Return Not this = that
    End Operator

    Public Shared Operator =(ByVal this As _pointer(Of T), ByVal that As _pointer(Of T)) As Boolean
        If that Is Nothing OrElse that.get() Is Nothing Then
            Return this Is Nothing OrElse this.get() Is Nothing
        Else
            Return this = that.get()
        End If
    End Operator

    Public Shared Operator <>(ByVal this As _pointer(Of T), ByVal that As T) As Boolean
        Return Not this = that
    End Operator

    Public Shared Operator =(ByVal this As _pointer(Of T), ByVal that As T) As Boolean
        If this Is Nothing Then
            Return that Is Nothing
        Else
            Return object_compare(this.get(), that) = 0
        End If
    End Operator

    Public Shared Operator <>(ByVal this As T, ByVal that As _pointer(Of T)) As Boolean
        Return Not this = that
    End Operator

    Public Shared Operator =(ByVal this As T, ByVal that As _pointer(Of T)) As Boolean
        Return that = this
    End Operator

    Public Shared Operator =(ByVal this As _pointer(Of T), ByVal obj As Object) As Boolean
        Dim that As _pointer(Of T) = Nothing
        that = cast(Of _pointer(Of T))(obj, False)
        If that Is Nothing Then
            Dim that2 As T = Nothing
            that2 = cast(Of T)(obj, False)
            Return this = that2
        Else
            Return this = that
        End If
    End Operator

    Public Shared Operator <>(ByVal this As _pointer(Of T), ByVal obj As Object) As Boolean
        Return Not this = obj
    End Operator

    Public Shared Operator =(ByVal this As Object, ByVal that As _pointer(Of T)) As Boolean
        Return that = this
    End Operator

    Public Shared Operator <>(ByVal this As Object, ByVal that As _pointer(Of T)) As Boolean
        Return Not this = that
    End Operator
End Class
